﻿using AnesSystem.Models.Model;
using AnesSystem.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
  public  class LaborEventAddViewModel:BaseViewModel<LaborEventAddViewModel>
    {
        #region Variables
        private PatientLaborEventModel _patientLaborEvent;
        private LaborEventAndMedicineCtrlViewModel _model;
        private LaborStatusItemViewModel _statusModel;



        #endregion


        #region Constructor

        #endregion


        #region Properties
        public PatientLaborEventModel PatientLaborEvent
        {
            get
            {
                return _patientLaborEvent;
            }

            set
            {
                _patientLaborEvent = value;
                RaisePropertyChanged("PatientLaborEvent");
            }
        }

        public LaborEventAndMedicineCtrlViewModel Model
        {
            get
            {
                return _model;
            }

            set
            {
                _model = value;
            }
        }

        public LaborStatusItemViewModel StatusModel
        {
            get
            {
                return _statusModel;
            }

            set
            {
                _statusModel = value;
            }
        }

        public string  Save()
        {
            PatientLaborEvent.BeginTime = PatientLaborEvent.BeginTime.AddSeconds(-PatientLaborEvent.BeginTime.Second).AddMilliseconds(-PatientLaborEvent.BeginTime.Millisecond);
            if (string.IsNullOrEmpty(PatientLaborEvent.Name))
            {
                MessageBoxCommon.ShowDialog("事件名称不能为空!", MessageBoxCommon.OK);
                return Constants.FAILED;
            }
            if (PatientLaborEvent.BeginTime<PatientLink.Status.InLaborTime)
            {
                MessageBoxCommon.ShowDialog("开始时间应该大于镇痛开始时间!", MessageBoxCommon.OK);
                return Constants.FAILED;
            }
            PatientLaborEvent.PatientID = PatientLink.Id.ToString();
            PatientLaborEvent.Code = PatientLaborEvent.Name;
            PatientLaborEvent.InputTime = DateTime.Now;
            Save2DB();
            RefreshWin();
            return Constants.SUCCESS;
        }

        private void RefreshWin()
        {
            Model.Refresh();
            StatusModel.Refresh();
        }

        private void Save2DB()
        {
            PatientLaborEventService.Instance.AddUpdate(PatientLaborEvent);
        }

        public void SaveContinue()
        {
            Save();
            PatientLaborEventModel ple = new PatientLaborEventModel();
            ple.Name = "";
            ple.BeginTime = DateTime.Now;
            PatientLaborEvent = ple;
        }

      

        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods


        #endregion


        #region Public/ProtectedMethods


        #endregion


        #region EventHandlers


        #endregion
    }
}
